// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "InputActionValue.h"
#include "AdvancedCharacterMovementComponent.h"
#include "CameraManager.h"
#include "GameSettingsManager.h"
#include "PlayerCharacter.generated.h"

/**
 * 玩家角色类
 * 实现第三人称角色控制、移动和相机系统
 */
UCLASS()
class EMPTYLAND_API APlayerCharacter : public ACharacter
{
    GENERATED_BODY()

public:
    // 构造函数
    APlayerCharacter();

protected:
    // 输入处理函数
    void Move(const FInputActionValue& Value); // 移动处理
    void Look(const FInputActionValue& Value); // 视角控制
    void Jump() override; // 跳跃重写
    void StopJumping() override; // 停止跳跃重写
    
    // 重写BeginPlay
    virtual void BeginPlay() override;

public:
    // 重写Tick
    virtual void Tick(float DeltaTime) override;

    // 绑定输入
    virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

private:
    // 相机管理器引用
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true"))
    ACameraManager* CameraManager;
    
    // 游戏设置管理器引用
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Settings", meta = (AllowPrivateAccess = "true"))
    UGameSettingsManager* GameSettingsManager;

    // 输入映射上下文
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
    class UInputMappingContext* DefaultMappingContext;

    // 移动输入动作
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
    class UInputAction* MoveAction;

    // 视角输入动作
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
    class UInputAction* LookAction;

    // 跳跃输入动作
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
    class UInputAction* JumpAction;

    // 冲刺输入动作
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input", meta = (AllowPrivateAccess = "true"))
    class UInputAction* SprintAction;

    /**
     * 获取高级移动组件
     * @return 高级角色移动组件指针
     */
    UFUNCTION(BlueprintCallable, Category = "Character")
    UAdvancedCharacterMovementComponent* GetAdvancedMovementComponent() const;

    /**
     * 处理冲刺输入
     * @param Value 输入动作值
     */
    void Sprint(const FInputActionValue& Value);

    /**
     * 获取冲刺状态
     * @return 是否在冲刺
     */
    UFUNCTION(BlueprintCallable, Category = "Character")
    bool IsSprinting() const;

    /**
     * 获取当前冲刺能量百分比
     * @return 冲刺能量百分比 (0.0 - 1.0)
     */
    UFUNCTION(BlueprintCallable, Category = "Character")
    float GetSprintEnergyPercentage() const;
    
    /**
     * 设置相机管理器
     * @param NewCameraManager 新的相机管理器
     */
    UFUNCTION(BlueprintCallable, Category = "Character")
    void SetCameraManager(ACameraManager* NewCameraManager);
    
    /**
     * 获取相机管理器
     * @return 相机管理器
     */
    UFUNCTION(BlueprintCallable, Category = "Character")
    ACameraManager* GetCameraManager() const;
    
    /**
     * 更新角色设置
     * 从游戏设置管理器应用设置到角色
     */
    UFUNCTION(BlueprintCallable, Category = "Character")
    void UpdateCharacterSettings();
};